package org.racsor.cc.action;

import java.net.URL;
import java.net.URLConnection;
import java.util.Date;
import java.util.logging.Logger;

import javax.jdo.PersistenceManager;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.racsor.cc.model.PMF;
import org.racsor.cc.model.RequestCC;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

@SuppressWarnings("serial")
public class ProxyRequest extends HttpServlet {
    private static final Logger log = Logger.getLogger(ProxyRequest.class.getName());

    public void doGet(HttpServletRequest req, HttpServletResponse resp) {

	try {
	    String url = (String) req.getParameter("url");
	    log.warning("url:" + url);

	    resp.setContentType("text/html; charset=ISO-8859-1");
	    resp.getWriter().println("Hello, ");
	    if (!StringUtils.isEmpty(url)) {
		URL connect = new URL(url);
		URLConnection connection = connect.openConnection();
		IOUtils.copy(connection.getInputStream(), resp.getWriter());
	    }

	} catch (Exception e) {
	    log.warning(ExceptionUtils.getStackTrace(e));
	}

    }
}
